package gew.table;

import gew.utils.SqlUtils;
import java.util.ArrayList;

public class TableColumn {
    private final int index;
    private final ArrayList<TableDimensionValue> dimValues;
    private final TableMeasure measure;

    public TableColumn(int index, TableMeasure measure) {
        this.index = index;
        this.dimValues = new ArrayList<>();
        this.measure = measure;
    }

    public TableColumn(int index, TableColumn column) {
        this(index, column.measure);
        for (int i = 0; i < column.dimValues.size(); i++){
            this.dimValues.add(column.dimValues.get(i));
        }
    }
    
    void addDimensionValue(TableDimensionValue v){
        this.dimValues.add(v);
    }
    
    public TableMeasure getMeasure(){        
        return measure;
    }
    
    String getSqlIfCondition(){
        String r = SqlUtils.SQL_ALWAYS_TRUE;
        for (int i = 0; i < dimValues.size(); i++){
            r = r
                    .concat(SqlUtils.SPACE)
                    .concat(SqlUtils.SQL_AND)
                    .concat(SqlUtils.SPACE)
                    .concat(SqlUtils.SQL_ALIAS_F)
                    .concat(SqlUtils.POINT)
                    .concat(dimValues.get(i).getTableDimension().getFactTableField())
                    .concat(SqlUtils.EQUALS)
                    .concat(dimValues.get(i).getId().toString());
        }
        return r;
    }

    public int getIndex() {
        return index;
    }

    public Iterable<TableDimensionValue> getDimValues() {
        return dimValues;
    }
    

}
